home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / src / java / net / socket~2.jav < prev    next >
Encoding:
Text File  |  1996-01-12  |  4.0 KB  |  138 lines

  1. /*
  2.  * @(#)SocketImpl.java    1.16 95/12/18 Jonathan Payne
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package java.net;
  21.  
  22. import java.io.IOException;
  23. import java.io.InputStream;
  24. import java.io.OutputStream;
  25. import java.io.FileDescriptor;
  26.  
  27. /**
  28.  * This is the Socket implementation class. It is an
  29.  * abstract class that must be subclassed to provide
  30.  * an actual implementation.
  31.  *
  32.  * @version     1.16, 12/18/95
  33.  * @author     Jonathan Payne
  34.  * @author     Arthur van Hoff
  35.  */
  36. public abstract class SocketImpl {
  37.  
  38.     /**
  39.      * The file descriptor object
  40.      */
  41.     protected FileDescriptor fd;
  42.     
  43.     /**
  44.      * The internet address where the socket will make a connection.
  45.      */
  46.     protected InetAddress address;
  47.    
  48.     /**
  49.      * The port where the socket will make a connection.
  50.      */
  51.     protected int port;
  52.     protected int localport;   
  53.  
  54.     /**
  55.      * Creates a socket with a boolean that specifies whether this
  56.      * is a stream socket or a datagram socket.
  57.      * @param stream a boolean indicating whether this is a stream
  58.      * or datagram socket
  59.      */
  60.     protected abstract void create(boolean stream) throws IOException;
  61.  
  62.     /**
  63.      * Connects the socket to the specified port on the specified host.
  64.      * @param host the specified host of the connection
  65.      * @param port the port where the connection is made
  66.      */
  67.     protected abstract void connect(String host, int port) throws IOException;
  68.  
  69.     /**
  70.      * Connects the socket to the specified address on the specified
  71.      * port.
  72.      * @param address the specified address of the connection
  73.      * @param port the specified port where connection is made
  74.      */
  75.     protected abstract void connect(InetAddress address, int port) throws IOException;
  76.  
  77.     /**
  78.      * Binds the socket to the specified port on the specified host.
  79.      * @param host the host
  80.      * @param port the port   
  81.      */
  82.     protected abstract void bind(InetAddress host, int port) throws IOException;
  83.  
  84.     /**
  85.      * Listens for connections over a specified amount of time.
  86.      * @param count the amount of time this socket will listen for 
  87.      * connections
  88.      */
  89.     protected abstract void listen(int count) throws IOException;
  90.  
  91.     /**
  92.      * Accepts a connection.
  93.      * @param s the accepted connection
  94.      */
  95.     protected abstract void accept(SocketImpl s) throws IOException;
  96.  
  97.     /**
  98.      * Gets an InputStream for this socket.
  99.      */
  100.     protected abstract InputStream getInputStream() throws IOException;
  101.  
  102.     /**
  103.      * Gets an OutputStream for this socket.
  104.      */
  105.     protected abstract OutputStream getOutputStream() throws IOException;
  106.  
  107.     /**
  108.      * Returns the number of bytes that can be read without blocking.
  109.      */
  110.     protected abstract int available() throws IOException;
  111.  
  112.     /**
  113.      * Closes the socket.
  114.      */
  115.     protected abstract void close() throws IOException;
  116.  
  117.     protected FileDescriptor getFileDescriptor() {
  118.     return fd;
  119.     }
  120.     protected InetAddress getInetAddress() {
  121.     return address;
  122.     }
  123.     protected int getPort() {
  124.     return port;
  125.     }
  126.     protected int getLocalPort() {
  127.     return localport;
  128.     }
  129.     
  130.     /**
  131.      * Returns the address and port of this Socket as a String.
  132.      */
  133.     public String toString() {
  134.     return "Socket[addr=" + getInetAddress() +
  135.         ",port=" + getPort() + ",localport=" + getLocalPort()  + "]";
  136.     }
  137. }
  138.